const PlayerInfo = (function () {
    // 构造函数
    function PlayerInfo() {
        this.playerId = 0;
        this.playerName = "";
        this.playerCoin = 0;
        this.headId = "2"
        this.gameInfo = [];
        this.ratio = 100;   // 游戏比例
        this.message = null;
        this.email = "";
        this.vip = 0;
        this.isGuest = 1;
        this.isFirstRecharge = 0;
        this.agentId = 0;
        this.isSignIn = 0;
        this.totalRecharge = 0;
        this.vipBonus = [];
        this.agentId = 0;
        this.inviterId = 0;
        this.sound = 0;

        // 读取缓存
        this.readFromCache = function (key) {
            if (typeof key !== 'string') {
                console.log("缓存键必须是字符串");
                return;
            }
            let info = cc.sys.localStorage.getItem(key);
            return info;
        };
        // 写入缓存
        this.writeToCache = function (key, value) {
            if (typeof key !== 'string') {
                console.log("缓存键必须是字符串");
                return;
            }
            cc.sys.localStorage.setItem(key, value);
        };

        this.playerHead = this.readFromCache("playerHead") ?? 1;
        this.isAutoLogin = this.readFromCache("isAutoLogin") ?? "false";
        this.sound = this.readFromCache("sound") ?? "true";
    }

    return PlayerInfo;
})();

module.exports = PlayerInfo;